﻿// *********************************************************************
// * Copyright © 2013 Scanvaegt Nordic A/S
// *
// * This file is the property of Scanvaegt Nordic A/S and may not be 
// * distributed without the written consent of the author.    
// ********************************************************************

using System.Data;
using Microsoft.Practices.Unity;
using SqlPad.Library.Interfaces;
using SqlPad.Library.Models;
using SqlPad.Library.QueryHandlers;
using SqlPad.Library.QueryTransformers;

namespace SqlPad.Library
{
    public class QueryFactory : IQueryFactory
    {
        protected IUnityContainer Container;

        public QueryFactory()
        {
            Container = new UnityContainer()
                    .RegisterType<IQueryHandler<DataTable>, SimpleQueryHandler>()
                    .RegisterType<IQueryTransform<DataTable>, HtmlTransformDataTable>()
                    .RegisterType<IQueryResult<DataTable>, DataTableQueryResult>()
                    .RegisterInstance<IQueryFactory>(this);
        }

        public IQueryHandler<T> CreateQuery<T>() where T : new()
        {
            return Container.Resolve<IQueryHandler<T>>();
        }

        public IQueryTransform<T> CreateTransform<T>() where T : new()
        {
            return Container.Resolve<IQueryTransform<T>>();
        }
    }
}